package com.lj.demo.eduservice.controller;


import com.lj.demo.commonutils.R;
import com.lj.demo.eduservice.entity.subject.OneSubject;
import com.lj.demo.eduservice.service.EduSubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;

import javax.security.auth.Subject;
import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author liujiang
 * @since 2020-11-30
 */
@Api(description = "课程分类管理")
//@CrossOrigin
@RestController
@RequestMapping("/eduservice/eduSubject")
public class EduSubjectController {

    @Autowired
    private EduSubjectService eduSubjectService;

    //添加课程分类
    @ApiOperation(value ="Excel批量导入")
    @PostMapping("addSubject")
    public R addSubject(MultipartFile file){
        //1.获取上传的Excel文件 MultipartFile
        //返回错误提示信息
        eduSubjectService.importSubjectDta(file,eduSubjectService);

        //判断返回集合是否为空
        return R.ok();
    }

    //获取课程分类
    @ApiOperation(value = "获取嵌套课程分类列表")
    @GetMapping("listSubject")
    public R listSubject(){
       List<OneSubject> oneSubjects =  eduSubjectService.nestedList();
        return R.ok().data("oneSubject",oneSubjects);
    }

}

